package com.yingjia.yingjiauniversity.utils;

import android.content.Context;
import android.widget.Toast;

import com.my.common.constant.ContextProvider;

public class ToastUtil {
    private static Toast toast;

    /**
     * 强大的吐司，能够连续弹的吐司
     *
     * @param text
     */
    public static void showToast(String text) {
        if (toast == null) {
            toast = Toast.makeText(ContextProvider.getInstance().getContext(), text, Toast.LENGTH_SHORT);
        } else {
            toast.setText(text);//如果不为空，则直接改变当前toast的文本
        }
        toast.show();
    }


    private ToastUtil() {
        throw new AssertionError();
    }

    /**
     * show text
     */

    public static void show(Context context, int resId) {
        show(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
    }

    public static void show(Context context, int resId, int duration) {
        show(context, context.getResources().getText(resId), duration);
    }

    public static void show(Context context, CharSequence text) {
        show(context, text, Toast.LENGTH_SHORT);
    }

    public static void show(Context context, CharSequence text, int duration) {
        Toast.makeText(context, text, duration).show();
    }

    public static void show(Context context, int resId, Object... args) {
        show(context, String.format(context.getResources().getString(resId), args), Toast.LENGTH_SHORT);
    }

    public static void show(Context context, String format, Object... args) {
        show(context, String.format(format, args), Toast.LENGTH_SHORT);
    }

    public static void show(Context context, int resId, int duration, Object... args) {
        show(context, String.format(context.getResources().getString(resId), args), duration);
    }

    public static void show(Context context, String format, int duration, Object... args) {
        show(context, String.format(format, args), duration);
    }

    /**
     * makeText
     */

    public static Toast makeText(Context context, int resId) {
        return makeText(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
    }

    public static Toast makeText(Context context, int resId, int duration) {
        return makeText(context, context.getResources().getText(resId), duration);
    }

    public static Toast makeText(Context context, CharSequence text) {
        return makeText(context, text, Toast.LENGTH_SHORT);
    }

    public static Toast makeText(Context context, CharSequence text, int duration) {
        return Toast.makeText(context, text, duration);
    }

    public static Toast makeText(Context context, int resId, Object... args) {
        return makeText(context, String.format(context.getResources().getString(resId), args), Toast.LENGTH_SHORT);
    }

    public static Toast makeText(Context context, String format, Object... args) {
        return makeText(context, String.format(format, args), Toast.LENGTH_SHORT);
    }

    public static Toast makeText(Context context, int resId, int duration, Object... args) {
        return makeText(context, String.format(context.getResources().getString(resId), args), duration);
    }

    public static Toast makeText(Context context, String format, int duration, Object... args) {
        return makeText(context, String.format(format, args), duration);
    }
}
